from datetime import datetime
from typing import Optional
from pydantic import BaseModel, Field, field_validator

from app.utils.tool import to_lower_camel


class OrderInSchema(BaseModel):
    create_time: Optional[datetime] = None
    order_id: Optional[str] = None
    create_at: Optional[str] = None
    client_id: Optional[str] = None
    qr_code: Optional[str] = None
    coupon_id: Optional[str] = None
    status: Optional[int] = None
    start_time: Optional[datetime] = Field(
        description="开始时间", alias="createdTime")


class OrderOutSchema(BaseModel):
    id: int
    coupon_id: Optional[int] = None
    coupon_name: str
    coupon_cate_name: str
    discount_amount: Optional[float] = None
    min_amount: Optional[float] = None
    start_time: datetime
    end_time: datetime
    created_time: datetime
    status: int

    # order_id: Optional[str] = None
    # client_name: Optional[str] = None
    # client_pone: Optional[str] = None
    # qr_code: Optional[str] = None

    # @field_validator("start_time", "end_time", "created_time", mode="before")
    # def datetime_format(cls, v):
    #     return v.strftime("%Y-%m-%d %H:%M:%S")

    # @field_validator("status", mode="after")
    # def validate_coupon_expiration(cls, v,args):
    #     # if v != 3 and v != 2 and cls.end_time and cls.end_time < datetime.now():
    #     #     return 3
    #     return v
    model_config = {
        "alias_generator": to_lower_camel,
        "populate_by_name": True,
    }


class OrderListInSchema(BaseModel):
    
    # client_phone = None
    coupon_cate_id: Optional[int] = None
    status: Optional[int] = 0
    model_config = {
        "alias_generator": to_lower_camel,
        "populate_by_name": True,
    }